<template>
  <div>
    <div style="padding:10px 0">
      <el-avatar :size="50" :src="userMsg.avatar"></el-avatar>
      <el-link type="info" :underline="false" style="font-size:17px;font-weight:700;line-height: 50px;vertical-align: top;">
        {{` ${userMsg.nickname}` }}
        <el-tag>{{userMsg.type == 1 ? "普通用户" : "专家用户"}}</el-tag>
      </el-link>
      <p style="marin:0 0;">个人简介:{{userMsg.introduce || "这个人很懒，没有填写简介~"}}</p>
      <el-button style="width:100%;" type="primary" plain @click="userMsg.openR=!userMsg.openR">私信Ta</el-button>
      <el-input type="textarea" v-show="userMsg.openR" :autosize="{ minRows: 5, maxRows: 10}" placeholder="请输入" v-model="userMsg.replyMsg" style="margin:10px 0;"></el-input>
      <el-button v-show="userMsg.openR" type="primary" @click="sendMsg">发送</el-button>
    </div>
  </div>
</template>

<script>
import { getUserMsg } from "@/api/front/user"
import {sendMsgToUser} from "@/api/front/msg"
export default {
  data() {
    return {
      userMsg: {}
    }
  },
  created() {
    this.getUm()
  },
  methods: {
    getUm() {
      getUserMsg({ objid: this.$route.query.objid }, (res) => {
        if (res.code == 200) {
          this.userMsg = {openR:false, replyMsg:""}
          Object.assign(this.userMsg,res.data)
        }
      })
    },
    sendMsg(){
      if(this.userMsg.replyMsg){
        sendMsgToUser({objid:this.userMsg.objid, content:this.userMsg.replyMsg}, (res) => {
          if(res.code == 200){
            this.userMsg.openR = !this.userMsg.openR
            this.userMsg.replyMsg = ""
          }
        }, true)
      }
      else{
        this.$message("请填写内容")
      }
    }
  }
}
</script>

<style lang="less" scoped>
</style>